package org.raymond.iworks.study.mq.rabbitmq.classic.priority;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.study.mq.rabbitmq.classic.notlose.DurableWorker;
import org.raymond.iworks.study.mq.rabbitmq.classic.ttl.TTLWork;

import java.nio.charset.StandardCharsets;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class NormalTask {

    public static void main(String[] args) throws Exception {
        String message = "1.";
        try(Connection connection = DurableWorker.connection();
            Channel channel = connection.createChannel()){
            channel.exchangeDeclare(HighPriorityWork.EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

            for(int i=0; i<5; i++){
                channel.basicPublish(HighPriorityWork.EXCHANGE_NAME, HighPriorityWork.ROUTING_KEY, null, message.getBytes(StandardCharsets.UTF_8));
            }
            log.info("[x] sent: {}:{}", TTLWork.ROUTING_KEY, message);
        }
    }
}
